package com.jinzecloud.reportapproval.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.jinzecloud.reportapproval.bean.InspResuPro;
import com.jinzecloud.reportapproval.dto.AuditParam;
import com.jinzecloud.reportapproval.dto.DataStagingParam;
import com.jinzecloud.reportapproval.enums.StateEnum;
import com.jinzecloud.reportapproval.service.AdminService;
import com.jinzecloud.reportapproval.vo.ProductInfoExportVoVo;
import com.jinzecloud.reportapproval.vo.ProductSpecificationExportVo;
import com.jinzecloud.reportapproval.vo.ProductSpecificationVo;
import com.jinzecloud.reportapproval.vo.ProductSpecificationVos;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import com.jinzecloud.reportapproval.bean.ProductSpecification;
import com.jinzecloud.reportapproval.service.ProductSpecificationService;
import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.R;



/**
 * 产品规格表
 *
 * @author æ­å°
 * @email 1971240051@qq.com
 * @date 2024-12-03 16:18:45
 */
@RestController
@RequestMapping("reportapproval/productspecification")
@RequiredArgsConstructor
public class ProductSpecificationController {
    @Autowired
    private ProductSpecificationService productSpecificationService;
    private final AdminService adminService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("reportapproval:productspecification:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = productSpecificationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("reportapproval:productspecification:info")
    public R info(@PathVariable("id") Integer id){
		ProductSpecificationVo productSpecification = productSpecificationService.getByProductSpecificationId(id);

        return R.ok().put("productSpecification", productSpecification);
    }

    /**
     * 信息
     */
    @RequestMapping("/getInfo/{number}")
    //@RequiresPermissions("reportapproval:productspecification:info")
    public R getInfo(@PathVariable("number") String number){
        List<ProductSpecificationVos> productSpecification = productSpecificationService.getByProductSpecificationNum(number);

        return R.ok().put("productSpecification", productSpecification);
    }

    @PostMapping("/review")
    public R review(@RequestBody ProductSpecification productSpecification) {
        productSpecificationService.updateById(new ProductSpecification().setId(productSpecification.getId()).setStatus(0));
        return R.ok();
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("reportapproval:productspecification:save")
    public R save(@RequestBody ProductSpecificationVo productSpecificationVo) throws IllegalAccessException {
        ProductSpecification productSpecification = new ProductSpecification().setProjectNumber(productSpecificationVo.getProjectNumber());
        productSpecification.setStatus(StateEnum.UN_SUBMIT.getState()).setWordPath("").setPdfPath("");
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        productSpecification.setUserId(adminService.getIdByName(authentication.getName()));
        R r = productSpecificationService.saveProductSpecification(productSpecificationVo,productSpecification);

        return r;
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("reportapproval:productspecification:update")
    public R update(@RequestBody ProductSpecificationVo productSpecificationVo) throws IllegalAccessException {
		productSpecificationService.updateProductSpecificationVoById(productSpecificationVo);

        return R.ok();
    }



    @PostMapping("/auditList")
    public R auditList(@RequestBody DataStagingParam param) {
        return R.ok().setData(productSpecificationService.auditList(param));
    }

    @RequestMapping(value = "/export/{id}",method = RequestMethod.POST)
    @ApiOperation(value = "检验报告信息",notes = "检验报告信息")
    //@RequiresPermissions("reportApproval:report:info")
    public R export(@PathVariable("id") Integer id){
        String path = productSpecificationService.getByIdproductInfoExportVo(id);

        return R.ok();
    }

    @PostMapping("/audit")
    public R audit(@RequestBody AuditParam auditParam) {
        return productSpecificationService.audit(auditParam);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("reportapproval:productspecification:delete")
    public R delete(@RequestBody Integer[] ids){
		productSpecificationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/viewPdf/{id}")
    public String viewPdf(@PathVariable("id") Integer id) {
        return productSpecificationService.viewPdf(id);
    }

    @RequestMapping("/viewWord/{id}")
    public String viewWord(@PathVariable("id") Integer id) {
        return productSpecificationService.viewWord(id);
    }
}
